package com.suge.tbapi.user;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.User;
import com.taobao.api.request.UserGetRequest;
import com.taobao.api.response.UserGetResponse;

public class TbUserApiManagerImpl implements TbUserApiManager{

	private static final Logger logger = LoggerFactory.getLogger(TbUserApiManagerImpl.class);
	
	private static final String appKey="";
	
	private static final String appSecret = "";
	
	public User getSingleTbUserInfo() {
		
		TaobaoClient client = new DefaultTaobaoClient("", appKey, appSecret);
        UserGetRequest req = new UserGetRequest();
        req.setFields("nick,sex,buyer_credit,seller_credit ,created,last_visit");
        req.setNick("andyy_tan");
        UserGetResponse response = null;
        try {
            response = client.execute(req); 
            logger.error("result:"+response.getBody());
            logger.error("nick:"+response.getUser().getNick());
        } catch (ApiException e) {
        	 logger.error(e.toString());
        }
        
        if(response!=null && response.isSuccess()){
        	return response.getUser();
        }
        return null;
	}

}
